package com.slipper.core.message;

import com.slipper.util.Tool;

import java.util.HashSet;
import java.util.Set;

public abstract class AbstractSubscriber implements Subscriber {
    private final Set<String> topicSet = new HashSet<>();

    public boolean hasTopic() {
        return !topicSet.isEmpty();
    }

    public boolean isTopic(String topic) {
        return topicSet.contains(topic);
    }

    public void addTopic(String topic) {
        if (Tool.isBlank(topic)) return;
        topicSet.add(topic);
    }

    public void removeTopic(String topic) {
        if (Tool.isBlank(topic)) return;
        topicSet.remove(topic);
    }

    public abstract void update(Message message);
}
